new Vue({
  el: '#app',
  data() {
    return {
      form: {
        // Article_Name: "",
        Type: "0",
        Group_Seek_Purchase_SerialNumber: '',
        token: $.cookie("token"),
        Enterprise_Info_SerialNumber: $.cookie("enterprise"),
        page: 1,			//页数
        limit: 10,			//每页数据条数
      },
      total: 0,
      flag: true,
      category: [],
      Enterprise: [],
      tableData: [],
      group_seek_transaction_logistics: {
        Group_Seek_Logistics_SerialNumber: '',  //主键
        Group_Seek_Transaction_SerialNumber: '',  //交易流水号
        Transport_Type: '',   //运输方式
        Transport_Explain: ''  //说明
      },
      OddNumbers: false,
      loading: false,
      // Enterprise_Info_SerialNumber: $.cookie("enterprise")
    }
  },
  mounted() {
    //默认查询第一组数据
    this.getList(this.form)
    //查询所有类别
    // this.getCategoryData()
    //查询所有发布过采购的公司
    // this.getEnterpriseData()
  },
  methods: {
    //通过关键字查询数据
    onSerach() {
      this.getList(this.form)
    },
    //号码按键查询
    handleSizeChange(val) {
      this.form.page = 1;
      this.form.limit = val;
      this.getList(this.form)
    },
    //号码按键查询
    handleCurrentChange(val) {
      this.form.page = val;
      this.getList(this.form)
    },
    //分页查询数据
    getList(data) {
      let _this = this
      $.ajax({
        type: 'POST',
        data,
        url: DomainName + '/getGroupSeekTransactionAllAction',
        success: function (Result) {
          _this.tableData = Result.tableData;
          console.log(Result)
          _this.total = parseInt(Result.limit)
        },
        complete: function (XMLHttpRequest) {
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        },
        dataType: "json"
      })
    },
    //  再次编辑
    goEditDetails(row) {
      sessionStorage.setItem("Group_Seek_Transaction_SerialNumber", row.Group_Seek_Transaction_SerialNumber)
      sessionStorage.setItem("Group_Seek_Purchase_SerialNumber", row.Group_Seek_Purchase_SerialNumber)
      window.location.href = './EditDetails.html'
      // window.location.href = './EditDetails.html'
    },
    // 详情
    goDetail(row) {
      console.log(row)
      sessionStorage.setItem("Group_Seek_Transaction_SerialNumber", row.Group_Seek_Transaction_SerialNumber)
      sessionStorage.setItem("Group_Seek_Purchase_SerialNumber", row.Group_Seek_Purchase_SerialNumber)
      window.location.href = './Detail.html'
    },
    // 确认合同
    ConfirmContract(row) {
      sessionStorage.setItem("Group_Seek_Transaction_SerialNumber", row.Group_Seek_Transaction_SerialNumber)
      sessionStorage.setItem("Group_Seek_Purchase_SerialNumber", row.Group_Seek_Purchase_SerialNumber)
      window.location.href = './ConfirmContract.html'
    },
    // 清空物流信息
    qing_group_seek_transaction_logistics() {
      this.group_seek_transaction_logistics = {
        Group_Seek_Logistics_SerialNumber: '',  //主键
        Group_Seek_Transaction_SerialNumber: '',  //交易流水号
        Transport_Type: '',   //运输方式
        Transport_Explain: ''  //说明
      }
    },
    // 代发货
    Consignment(row) {
      this.group_seek_transaction_logistics.Transport_Type = row.Transport_Type
      this.group_seek_transaction_logistics.Group_Seek_Transaction_SerialNumber = row.Group_Seek_Transaction_SerialNumber
      this.OddNumbers = true
      let _this = this;
      let obj = {
        // 采购信息表
        group_seek_transaction: {
          group_seek_transaction_paystages: {}
        }
      }
      $.ajax({
        url: DomainName + '/getSubtableInquiryOriginal',
        type: 'POST',
        data: {
          Primary_Key: row.Group_Seek_Transaction_SerialNumber,
          JSONObject: JSON.stringify(obj),
          token: $.cookie("token")
        },
        success: function (res) {
          console.log(res)
          _this.formData = res.group_seek_transaction[0]
        }
      })
    },
    // 确认发货
    addOddNumbers() {
      let _this = this
      let year = new Date().getFullYear();
      let month = new Date().getMonth() + 1;
      let days = new Date().getDate();
      let hour = new Date().getHours()
      let minutes = new Date().getMinutes()
      let second = new Date().getSeconds()
      if (month < 10) { month = '0' + month }
      if (days < 10) { days = '0' + days }
      if (hour < 10) { hour = '0' + hour }
      if (minutes < 10) { minutes = '0' + minutes }
      if (second < 10) { second = '0' + second }
      var times = year + '-' + month + '-' + days + ' ' + hour + ':' + minutes + ':' + second
      var group_message_buyer = {
        Group_Message_SerialNumber: "",
        Group_Transaction_SerialNumber: _this.formData.Group_Transaction_SerialNumber,
        Cause: "已发货",
        Submission_Time: times,
        Enterprise_Info_SerialNumber: $.cookie("enterprise"),
        Seller_Type: "0"
      }
      _this.formData.Row_Status = '5'
      let data = { Data: JSON.stringify({ Modify: { group_seek_transaction: [_this.formData] }, Add: { group_seek_transaction_logistics: [_this.group_seek_transaction_logistics] }, Add: { group_message: [group_message_buyer] } }), token: $.cookie("token") }
      console.log(_this.group_seek_transaction_logistics)
      $.ajax({
        url: DomainName + '/getEditAction',
        type: 'POST',
        data,
        success: function (res) {
          console.log('提交结果', res)
          _this.$message.success("已发货")
          _this.OddNumbers = false
        },
        error: function () {
          _this.$message.error("操作失败，请稍后再试")
        },
        complete: function (XMLHttpRequest) {
          _this.loading = false
          if (XMLHttpRequest.getResponseHeader("REDIRECT") == "REDIRECT") {
            window.parent.document.location.href = "../../../" + XMLHttpRequest.getResponseHeader("CONTENTPATH");
          }
        }
      })
    }
  },
})

